<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
    <script src="vue.min.js"></script>
    <script src="https://cdn.bootcss.com/vue-router/3.1.2/vue-router.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        #app {
            width: 100%;
            height: 100vh;
            background: #1b6d85;
            position: relative;
        }

        .app_son {
            width: 300px;
            height: 300px;
            /*border: 1px solid black;*/
            background: yellow;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
        .router-link{
            width: 100%;
            height: 3rem;
            /*background: red;*/
            display: flex;
            align-items: center;
        }
        .router-link span{
            width: 50%;
            height: 3rem;
            text-align: center;
            line-height: 3rem;
        }

        .router-link-active{
            width: 100%;
            height: 3rem;
            background: gray;
            color: blue;
            font-size: 1rem;
            border: 3px solid gray;
        }

        .text {
            width: 100%;
            /*background: red;*/
            height: 2rem;
            display: flex;
            align-items: center;
            cursor: pointer;
            border-bottom: 1px solid black;
        }

        .text1 {
            display: block;
            width: 50%;
            height: 2rem;
            text-align: center;
            line-height: 2rem;
        }

        .login1, .register1 {
            width: 100%;
            padding-top: 20px;
            /*height/: 20vh;*/
            padding-bottom: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;

        }
        .login1 p, .register1 p{
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .input {
            width: 80%;
            height: 2rem;
            padding-left: 4px;
            /*margin-left: 35%;*/
            margin-bottom: 20px;
            /*margin: 20px auto;*/
        }

        .input1 {
            width: 90px;
            height: 2rem;
            /*margin-left: 45%;*/
        }

        .v-enter, .v-leave-to {
            opacity: 0;
            transform: translateY(20px);
        }

        .v-enter-active, .v-leave-active {
            transition: all 0.5s ease;
        }

    </style>
</head>
<body>

<div id="app">
    <div class="app_son">
        <div class="router-link">
            <router-link to="/login" tag="span">登录</router-link>
            <router-link to="/zhuce" tag="span">注册</router-link>
        </div>

        <transition mode="out-in">
            <router-view></router-view>
        </transition>
    </div>
</div>


<script>
    //组件模板对象
    var login = {
        template: '<div class="login1" style="margin-top: 10px;">' +
        '<p style="margin-top:14px"><input type="text" placeholder="请填写账号" class="input"/></p>' +
        '<p style="margin-top:14px"><input type="text" placeholder="请填写密码" class="input"/></p>' +
        '<p style="margin-top:14px"><input type="button" value="登录" class="input1"/></p>' +
        '</div>',
    };
    var zhuce = {
        template: '<div class="register1" style="margin-top: 10px;">' +
        '<p><input type="text" placeholder="请填写手机号" class="input"/></p>' +
        '<p><input type="text" placeholder="请填写邮箱" class="input"/></p>' +
        '<p><input type="text" placeholder="请填写密码" class="input"/></p>' +
        '<p><input type="button" value="注册" class="input1"/></p>' +
        '</div>',
    };

    var routerObj = new VueRouter({
        routes: [//路由匹配规则
            {path: '/', redirect: '/login'},//强制重新定向
            {path: '/login', component: login},
            {path: '/zhuce', component: zhuce},
        ]
    });


    let app = new Vue({
        el: '#app',
        data() {
            return {
                message: '我爱你 Vue!'
            }
        },
        methods: {},
        router: routerObj,
        watch:{
            '$route.path':function (newVal, oldVal) {
                if(newVal==='/login'){
                    setTimeout(() => {
                        alert('欢迎进入登录页面')
                    },1000)
                }else{
                    setTimeout(() => {
                        alert('欢迎进入注册页面')
                    },1000)
                }
            }
        }
    })
</script>
</body>
</html>